package com.ruifu.bom.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.ruifu.bom.dto.MaterielImportDTO;
import com.ruifu.bom.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 导入文档数据
 *
 * @author gqx
 */
@RestController
@CrossOrigin
@RequestMapping("/materielImport")
public class MaterielImportController {
    @Autowired
    private MaterielService materielService;
    @Autowired
    private MaterielStructureService structureService;
    @Autowired
    private MeteringUnitsService meteringUnitsService;

    @PostMapping("/save")
    public R save(@RequestBody List<MaterielImportDTO> materielImportDTOList) {
        try {
            materielService.saveImport(materielImportDTOList);
            structureService.saveImport(materielImportDTOList);
            meteringUnitsService.unitsName(materielImportDTOList);
            return R.ok("导入成功");
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.getMessage());
        }
    }
}
